﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StructureMap;
using App.Account.DataAccess.Interfaces;
using App.Account.DataAccess.SqlServer;
using System.Configuration;
using App.Account.Services;
using App.Utility;
using System.Web.Routing;
using System.Web.Mvc;
using App.Account.HttpModules;
using System.Web;

namespace App.Account
{
    [Pluggable("App.Account")]
    public class Plugin : IPluggable
    {
        public static RoleAuthenticationModule Module = new RoleAuthenticationModule();
        public void ConfigurePlugin(string ServiceLocation)
        {
            // configure sql
            ObjectFactory.Configure(x =>
                {
                    x.ForRequestedType<IAccountRepository>().TheDefaultIsConcreteType<SqlAccountRepository>();
                });

            if (ServiceLocation.ToLower() == "remote")
                ObjectFactory.Configure(x =>
                    {
                        x.ForRequestedType<IAccountService>().TheDefaultIsConcreteType<AccountServiceClient>();
                    });
            else
                ObjectFactory.Configure(x =>
                    {
                        x.ForRequestedType<IAccountService>().TheDefaultIsConcreteType<AccountService>();
                    });

            RouteTable.Routes.MapRoute(
                "AccountAdmin",
                "Admin/Account/{action}/{id}",
                new { controller = "AccountAdmin", action = "Index", id = "" }
                );


        }

        public void InitPlugin(HttpApplication App)
        {
            Module.Init(App);
        }

    }
}
